package com.demo.websocket;

import java.util.Map;

import org.springframework.stereotype.Component;

import com.corundumstudio.socketio.AckRequest;
import com.corundumstudio.socketio.SocketIOClient;
import com.google.gson.Gson;
import com.outstading.plugin.netty.socketio.HandlerUtils;
import com.outstading.plugin.netty.socketio.JsonMessageHandler;
import com.outstading.plugin.netty.socketio.MessageHandler;
import com.outstading.plugin.netty.socketio.ObjectMessageHandler;
import com.outstading.plugin.netty.socketio.SocketSender;
import com.outstanding.framework.base.TransactionLogger;
import com.outstanding.framework.core.PendingException;

@Component
public class TalkHandler extends  ObjectMessageHandler{

	

	

	@Override
	public String messageType() {
		return "send";
	}

	

	@Override
	public void onMessage(SocketIOClient client, Object data, AckRequest ackRequest) throws PendingException {
		Map map = (Map)data;
		Words newws = new Words();
		newws.setId((String)map.get("id"));
		newws.setText("我已经收到了"+(String)map.get("text"));
		String uuid= HandlerUtils.getUUID(client);
		TransactionLogger.debug(uuid+"发来了"+(String)map.get("text"));
		SocketSender.sendMessageToUser(uuid, "reply", newws);
		
	}



	@Override
	public Class dataClass() {
		
		return Object.class;
	}



	

	
	

}
